package top.wnma.crud.dao.impl;

import java.io.Serializable;
import java.util.List;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import top.wnma.crud.dao.DepartmentDao;
import top.wnma.crud.pojo.Department;

@Repository
public class DepartmentDaoImpl extends HibernateDaoSupport  implements DepartmentDao {

	@Resource
	public void setMySessionFactory(SessionFactory sessionFactory) {
		super.setSessionFactory(sessionFactory);
	}
	
	public void save(Department department) {
		this.getHibernateTemplate().save(department);
	}

	public void delete(Department department) {
		this.getHibernateTemplate().delete(department);
		
	}

	public void update(Department department) {
		this.getHibernateTemplate().update(department);
		
	}

	public void saveOrUpdate(Department department) {
		this.getHibernateTemplate().saveOrUpdate(department);
		
	}

	public Department findById(Serializable id) {
		return this.getHibernateTemplate().get(Department.class, id);
	}

	public List<Department> findAll() {
		String hql="from Department";
		return (List<Department>) this.getHibernateTemplate().find(hql);

	}
	
	

}
